/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package struts;

import Service.PlanService;
import Service.PlanServiceImpl;
import java.util.*;
import javabeans.Event;
import javabeans.Plan;

/**
 *
 * @author zhi
 */
public class PlanInfo {
    int planid;
    String planname;
    String plandescript;
    List<EventInfo> eventInfos;

    public List<EventInfo> getEventInfos() {
        return eventInfos;
    }

    public void setEventInfos(List<EventInfo> eventInfos) {
        this.eventInfos = eventInfos;
    }

    public String getPlandescript() {
        return plandescript;
    }

    public void setPlandescript(String plandescript) {
        this.plandescript = plandescript;
    }

    public int getPlanid() {
        return planid;
    }

    public void setPlanid(int planid) {
        this.planid = planid;
    }

    public String getPlanname() {
        return planname;
    }

    public void setPlanname(String planname) {
        this.planname = planname;
    }


    public void saveThisPlan() {
        PlanService ps = new PlanServiceImpl();
System.out.println(planid);
        Plan thisplan = ps.getPlan(planid);
        if(thisplan == null) {
            System.out.println("null!");
        }
        //thisplan.setPlanid(id);
        thisplan.setPlanname(planname);
        thisplan.setPlandescript(plandescript);
        
        for(int i=0;i<eventInfos.size();i++) {
            EventInfo ei = eventInfos.get(i);
            String operation = ei.getOperation();
            if("new".equals(operation)){
                Event e = ei.getEvent();
System.out.println("new event: " + e.getId());
System.out.println("new event: " + e.getEventdate());
                ps.addEvent(e.getEventname(), e.getType(), e.getEventdate(), e.getEventtime(), e.getEventdescript(), e.getPointX(), e.getPointY(), e.getColor(), thisplan);
            } else if("modify".equals(operation)) {
                Event e = ei.getEvent();
System.out.println("modify event: "+e.getId());
                ps.modifyEvent(e.getId(), e.getEventname(), e.getType(), e.getEventdate(), e.getEventtime(), e.getEventdescript(), e.getPointX(), e.getPointY(), e.getColor(), thisplan);
            } else if("delete".equals(operation)) {
                Event e = ei.getEvent();
System.out.println("delete event: "+e.getId() + "planid: " + thisplan.getPlanid());
                boolean s = ps.deleteEvent(e.getId(), thisplan.getPlanid());
System.out.println("delete event: "+s);
            }

        }
    }

}
